﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebShopData;

namespace GalaxySale2014
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Order currentOrder = Session["CurrentOrder"] as Order;
                SetLabelTexts(currentOrder);

                GridViewConfirmationOverview.DataSource = currentOrder.OrderRows;
                GridViewConfirmationOverview.DataBind();

                LabelTotalSum.Text = string.Format("Total sum: {0:C0}", currentOrder.TotalSum);
            }
        }

        private void SetLabelTexts(Order currentOrder)
        {
            LabelFirstNameValue.Text = currentOrder.FirstName;
            LabelLastNameValue.Text = currentOrder.LastName;
            LabelAddressValue.Text = currentOrder.Address;
            LabelCityValue.Text = currentOrder.City;
            LabelZipValue.Text = currentOrder.Zip;
            LabelEmailValue.Text = currentOrder.Email;
        }

        protected void ButtonBackToCart_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Cart.aspx");
        }

        protected void ButtonConfirmOrder_Click(object sender, EventArgs e)
        {
            Order currentOrder = Session["CurrentOrder"] as Order;
            OrderDB.InsertNewOrder(currentOrder);
            currentOrder.OrderRows.Clear();
            Response.Redirect("~/ThankYou.aspx");
        }
    }
}